package com.neuedu.web.dao;

import com.neuedu.web.common.BaseDao;
import com.neuedu.web.po.ConstantsTypePO;
import com.neuedu.web.po.ConstantsTypePO;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.List;

/**
 * @author 金山
 * 项目：his-server
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2024/11/2113:35
 */
public class ConstantsTypeDao extends BaseDao<ConstantsTypePO> {


    public List<ConstantsTypePO> selectAll(String sql, Object... params) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        return super.selectAll(ConstantsTypePO.class, sql, params);
    }

    public List<ConstantsTypePO> selectPage(int current, int size, String sql, Object... params) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        return super.selectPage(ConstantsTypePO.class, current, size, sql, params);
    }


    public ConstantsTypePO selectById(long id) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {


        String sql = "select * from constant_type where type_id= ?";
        return super.selectOne(ConstantsTypePO.class, sql, id);

    }


    public int insert(ConstantsTypePO po) {
        String sql = "INSERT INTO  `constant_type` (   `type`, `caption`) VALUES(  ?,? )  ";
        int count = super.update(sql,
                po.getType(),
                po.getCaption()
        );

        return count;

    }


    public int update(ConstantsTypePO po) {
        StringBuffer sql = new StringBuffer();

        sql.append(" update 					");
        sql.append("   `constant_type` 			");
        sql.append(" set			");
        sql.append("   `type` = ?,			");
        sql.append("   `caption` = ?			");

        sql.append(" where `type_id` =  ?			");


        int count = super.update(sql.toString(),
                po.getType(),
                po.getCaption(),
                po.getTypeId()
        );

        return count;

    }

    /**
     * 通用的方法
     *
     * @return
     */

    public int delete(long id) {
        StringBuffer sql = new StringBuffer();

        sql.append(" delete from constant_type where type_id = ?");

        int count = super.update(sql.toString(), id);

        return count;

    }


}